package com.aepryus.loom;

import java.lang.reflect.*;
import java.beans.*;
import java.util.*;

public class DomainInfo<T extends Domain> {
	private Map<String,Method> setters = new HashMap<String,Method>();
	private Map<String,Method> getters = new HashMap<String,Method>();
	private Constructor<T> constructor;

	public DomainInfo (Class domain) {
		try {
			BeanInfo info = Introspector.getBeanInfo(domain);
			for (PropertyDescriptor pd : info.getPropertyDescriptors()) {
				if (pd.getWriteMethod() != null)
					setters.put(pd.getName(),pd.getWriteMethod());
				if (pd.getReadMethod() != null)
					getters.put(pd.getName(),pd.getReadMethod());
			}
			constructor = (Constructor<T>)domain.getConstructor(new Class[]{});

		} catch (NoSuchMethodException e) { //
		} catch (IntrospectionException e) {
			throw new RuntimeException(e);
		}
	}
	Method getSetter (String property) {
		return setters.get(property);
	}
	Method getGetter (String property) {
		return getters.get(property);
	}
	Constructor<T> getConstructor () {
		return constructor;
	}
}

